<?php


namespace App\Controller\Cooperative;


use App\Annotation\OperationLog;
use App\Controller\AbstractController;
use App\Request\Cooperative\TaskTypeSaveRequest;
use App\Service\Cooperative\TaskTypeService;
use Hyperf\Di\Annotation\Inject;

class TaskTypeController extends AbstractController
{

    /**
     * @Inject()
     * @var TaskTypeService
     */
    protected $taskTypeService;

    /**
     * @OperationLog(event="配置中心-类型列表",platform="cooperative")
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function index()
    {
        $index = $this->taskTypeService->index();
        return $this->response->success($index);
    }

    /**
     * @OperationLog(event="配置中心-添加/修改类型",platform="cooperative")
     * @param $id
     * @param TaskTypeSaveRequest $request
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function save($id, TaskTypeSaveRequest $request)
    {
        $validated = $request->validated();
        $type = $this->taskTypeService->save($id, $validated);
        return $this->response->success($type);
    }

    /**
     * @OperationLog(event="配置中心-删除类型",platform="cooperative")
     * @param int $id
     * @return mixed|\Psr\Http\Message\ResponseInterface
     * @throws \Exception
     */
    public function delete(int $id)
    {
        $data = $this->taskTypeService->delete($id);
        return $this->response->success($data);
    }
}